{% extends 'myadmin/index.html'%}

{% block title %}
<title>后台会员列表</title>
{% endblock %}

{% block con%}
<div class="widget-body  am-fr">

    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
        <div class="am-form-group">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                    <a href="{% url 'cates_add' %}" type="button" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</a>
                    <button type="button" class="am-btn am-btn-default am-btn-secondary"><span class="am-icon-save"></span> 保存</button>
                    <button type="button" class="am-btn am-btn-default am-btn-warning"><span class="am-icon-archive"></span> 审核</button>
                    <button type="button" class="am-btn am-btn-default am-btn-danger"><span class="am-icon-trash-o"></span> 删除</button>
                </div>
            </div>
        </div>
    </div>
     <form>
    <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
        <div class="am-form-group tpl-table-list-select">
            <select data-am-selected="{btnSize: 'sm'}" style="display: none;" name="types">
                <option value="all" {% if request.GET.types == 'all' %} selected {% endif %}>全局搜索</option>
              <option value="id" {% if request.GET.types == 'id' %} selected {% endif %}>ID</option>
              <option value="name" {% if request.GET.types == 'name' %} selected {% endif %}>分类名</option>

              <!--<option value="all">全局搜索</option>-->
               <!--<option value="id">id</option>-->
                 <!--<option value="name">分类名</option>-->
            </select>
        </div>
    </div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">

        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
            <input type="text" class="am-form-field" name="keyword" value="{{request.GET.keyword}}">
            <span class="am-input-group-btn">
                <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"></button>
              </span>
        </div>

    </div>
     </form>
    <div class="am-u-sm-12">
        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
            <thead>
                <tr>
                 <th>ID</th>
                    <th>分类名</th>
                    <th>所属父级</th>
                    <th>Path路径</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
            {% for i in userlist%}
                <tr class="gradeX">
                    <td class="am-text-middle">{{i.id}}</td>
                    <!--sub 是美化标识符  name 是当前元素的name  pname是父级元素的name-->
                     <td class="am-text-middle newname">{{i.sub}}<span cid="{{i.id}}">{{i.name}}</span></td>
                     <td class="am-text-middle">{{i.pname}}</td>
                     <td class="am-text-middle">{{i.path}}</td>
                    <td class="am-text-middle">
                        <div class="tpl-table-black-operation">
                             <a href="javascript:void(0)" cid="{{ i.id }}" class="removeCate tpl-table-black-operation-del del">
                                <i class="am-icon-pencil"></i> 删除
                            </a>
                        </div>
                    </td>
                </tr>
            {% endfor %}
                <!-- more data -->
            </tbody>
        </table>
    </div>
    <div class="am-u-lg-12 am-cf">

        <div class="am-fr">
            <ul class="am-pagination tpl-pagination">
                    {% load pagetag %}
                <!--调用自定义标签函数  第一个参数是总条目 第二个参数是当前的页数(request是后台接受的get参数)  -->
             {% showpage userlist.paginator.num_pages request %}
            </ul>
        </div>
    </div>
</div>
<script>
    $('.del').click(function(){
        //alert('1')
        //获取父级元素 用来在ajax中使用
        then=$(this).parents('tr')
        var cid=$(this).attr('cid')
        $.get('{% url 'cates_del'%}',{'cid':cid},function(data){
            if(data['msg']=='删除成功')
                then.remove()
            alert(data['msg'])
        },'json')
    })

    $('.newname').dblclick(function(){
        //alert('1')
        //获得span标签
        var span=$(this).find('span')
        //获的span标签中的内容
        var catename=span.text()
        //创建input标签
         var inp = $('<input type="text" style="color:black;" value="'+catename+'">')
        //替换内容
        $(this).find('span').html(inp)
        //选中状态
         inp.select()
        //获取当前选择的id (这行的id)
        var cid=span.attr('cid')
        inp.blur(function(){
            //获得input框的值
            var newname=$(this).val()
            $.get('{% url 'cates_update' %}',{'cid':cid,'newname':newname},function(data){
                span.html(newname)
                alert(data['msg'])
            },'json')
        })
    })

 $(document).ready(function(){
   $('#shangpinfenlei').click()
})

</script>
{%endblock%}